/* Create plots to compare the power functions for experts vs the estimators.
Use two-way clustering method to address concerns about SEs.
*/

clear
set more off
set scheme  s1mono 

cd "${main}"

cap log close _all
log using "${logs}/estimators_v_human_rd_experts_twoway_clustering.log", replace								


*=============================================================
/*Define a program to produce power function comparison graphs
============================================================*/
cap program drop pf_comp_2w
program define pf_comp_2w
	args r 
	
	replace y = `r' if human == 0

	forvalues i = 1/6 {
		cgmreg y human if d`i', cluster(pid dgp_by_seed)
		local diff`i' = _b[human]
		matrix temp = r(table)
		local cl`i' = temp[5, 1]
		local cu`i' = temp[6, 1]
		local diffSignif`i' = (`cl`i'' > 0 | `cu`i'' < 0) & (`cl`i'' != .)
		local betay`i' = temp[1, 1] + temp[1, 2]
		local betar`i' = temp[1, 2]
	}

drop _all
set obs 6

gen disc = _n - 1
label values disc disc_lab

*Create cardinal discontinuity
gen discc = 0 if disc == 0
replace discc = 0.1944 if disc == 1
replace discc = 0.324 if disc == 2
replace discc = 0.54 if disc == 3
replace discc = 0.9 if disc == 4
replace discc = 1.5 if disc == 5

gen diff = .
gen cu = .
gen cl = .
gen diffSignif = .
gen betar = .
gen betay = .

forvalues num = 1/6 { 
	di `i'
	di `diff`num''
	replace diff = `diff`num'' if disc == `num'-1
	replace cu = `cu`num'' if disc == `num'-1
	replace cl = `cl`num'' if disc == `num'-1
	replace diffSignif = `diffSignif`num'' if disc == `num'-1
	replace betar = `betar`num'' if disc == `num'-1 
	replace betay = `betay`num'' if disc == `num'-1 
					 }
					 
* Multiply by -1 to get estimator minus human results
replace diff = diff * -1
replace cu = cu * -1
replace cl = cl * -1
 
end


*=========================================================================	

/*========================================================================
*Import full set of estimates:
-------------------------------------------*/

cd "${main}"

use "${dat}/expert_merged_rd_estimates_micro.dta", clear

*Modify discontinuity variable:
 
replace abs_disc = round(abs_disc,0.0001)

cap drop disc
gen disc  = 0 if abs_disc<=0.01
replace disc = 4 if abs_disc>=0.89 & abs_disc<=0.91
replace disc = 5 if abs_disc>=1.49
replace disc = 3 if abs_disc>=0.53 & abs_disc<=0.55
replace disc = 2 if abs_disc>=0.32 & abs_disc<=0.33
replace disc = 1 if abs_disc>=0.19 & abs_disc<=0.2

label define disc_lab 0 "0" 1 "0.1944" 2 "0.324" 3 "0.54" 4 "0.9" 5 "1.5"
label values disc disc_lab
tabulate disc, gen(d)

*Create cluster ID:
split filename, p("_")
rename filename7 playergraph_seed
egen dgp_by_seed = group(playerdgp playergraph_seed)
egen player = group(pid)

*Piecewise quintic estimates:
gen reject_pq = 1 
replace reject_pq = 0 if D_cl <= 0 & D_cu  >= 0
replace reject_pq = . if  D_cl == . | D_cu  == .
* Piecewise quintic size-adjusted
gen reject_pq_sa = abs(D / D_se)
replace reject_pq_sa = reject_pq_sa > 1.9520415
*Rdrobust, theoretical bandwidth adjusted for asymptotic bias
gen reject_c_theor_bw = 1 
replace reject_c_theor_bw = 0 if rd_c_cl_cct_theor_bw  <= 0 & rd_c_cu_cct_theor_bw   >= 0
replace reject_c_theor_bw = . if  rd_c_cl_cct_theor_bw  == . | rd_c_cu_cct_theor_bw   == .
* Rdrobust default (conventional, MSE)
gen reject_c = 1
replace reject_c = 0 if rd_c_cl_mse <= 0 & rd_c_cu_mse >= 0
replace reject_c = . if rd_c_cl_mse == . | rd_c_cu_mse == .
*Rdrobust, bias corrected, MSE
gen reject_bc = 1 
replace reject_bc = 0 if rd_r_cl_mse  <= 0 & rd_r_cu_mse   >= 0
replace reject_bc = . if  rd_r_cl_mse  == . | rd_r_cu_mse   == .
*Rdrobust, theoretical bandwidth, robust SEs, bias-correction
gen reject_r_theor_bw = 1 
replace reject_r_theor_bw = 0 if rd_r_cl_cct_theor_bw  <= 0 & rd_r_cu_cct_theor_bw   >= 0
replace reject_r_theor_bw = . if  rd_r_cl_cct_theor_bw  == . | rd_r_cu_cct_theor_bw   == .
* Rdrobust, bias-corrected size-adjusted
gen reject_bc_sa = 1 
gen rd_r_cl_mse_sa = rd_bc_mse - 2.2816997 * rd_r_se_mse
gen rd_r_cu_mse_sa = rd_bc_mse + 2.2816997 * rd_r_se_mse
replace reject_bc_sa = 0 if rd_r_cl_mse_sa  <= 0 & rd_r_cu_mse_sa   >= 0
replace reject_bc_sa = . if  rd_r_cl_mse_sa  == . | rd_r_cu_mse_sa  == .
*Rdrobust, conventional, IK
gen reject_cik = 1 
replace reject_cik = 0 if rd_c_cl_ik <= 0 & rd_c_cu_ik   >= 0
replace reject_cik = . if  rd_c_cl_ik == . | rd_c_cu_ik   == .
*Rdrobust, conventional, IK with theoretically optimal bandwidth
gen reject_cik_theor_bw = 1 
replace reject_cik_theor_bw = 0 if rd_c_cl_ik_theor_bw <= 0 & rd_c_cu_ik_theor_bw   >= 0
replace reject_cik_theor_bw = . if  rd_c_cl_ik_theor_bw == . | rd_c_cu_ik_theor_bw   == .
*Rdrobust, conventional, IK with theoretically optimal bandwidth and size-adjusted using 2.18 critical value
gen reject_cik_theor_bw_sa_218 = 1 
gen rd_c_cl_ik_theor_bw_sa_218 = rd_c_ik_theor_bw - 2.18 * rd_c_se_ik_theor_bw
gen rd_c_cu_ik_theor_bw_sa_218 = rd_c_ik_theor_bw + 2.18 * rd_c_se_ik_theor_bw
replace reject_cik_theor_bw_sa_218 = 0 if rd_c_cl_ik_theor_bw_sa_218  <= 0 & rd_c_cu_ik_theor_bw_sa_218   >= 0
replace reject_cik_theor_bw_sa_218 = . if rd_c_cl_ik_theor_bw_sa_218  == . | rd_c_cu_ik_theor_bw_sa_218  == .
* Experts vs IK and CCT robust (both size-adjusted)
gen reject_cik_sa = 1 
gen rd_c_cl_ik_sa = rd_c_ik - 2.4640732 * rd_c_se_ik
gen rd_c_cu_ik_sa = rd_c_ik + 2.4640732 * rd_c_se_ik
replace reject_cik_sa = 0 if rd_c_cl_ik_sa  <= 0 & rd_c_cu_ik_sa   >= 0
replace reject_cik_sa = . if  rd_c_cl_ik_sa  == . | rd_c_cu_ik_sa  == .
* IK (size-adjusted to 2.18)
gen reject_cik_sa_218 = 1 
gen rd_c_cl_ik_sa_218 = rd_c_ik - 2.18 * rd_c_se_ik
gen rd_c_cu_ik_sa_218 = rd_c_ik + 2.18 * rd_c_se_ik
replace reject_cik_sa_218 = 0 if rd_c_cl_ik_sa_218  <= 0 & rd_c_cu_ik_sa_218   >= 0
replace reject_cik_sa_218 = . if  rd_c_cl_ik_sa_218  == . | rd_c_cu_ik_sa_218  == .
*Rdrobust, conventional, CER
gen reject_c_cer = 1 
replace reject_c_cer = 0 if rd_c_cl_cer  <= 0 & rd_c_cu_cer   >= 0
replace reject_c_cer = . if  rd_c_cl_cer  == . | rd_c_cu_cer   == .
*Rdrobust, robust, CER
gen reject_r_cer = 1 
replace reject_r_cer = 0 if rd_r_cl_cer  <= 0 & rd_r_cu_cer   >= 0
replace reject_r_cer = . if  rd_r_cl_cer  == . | rd_r_cu_cer   == .

tempfile full
save "`full'"

* Structure data: observations we want to use humans for, and estimator obs (stacked regressions)
preserve
gen human = 1
egen pid_num = group(pid)
drop pid
gen pid = pid_num + 10000
drop pid_num
tempfile d
save "`d'", replace
restore

drop pid
gen pid = _n + 20000
gen human = 0
append using "`d'"

*=========================================================

* Piecewise quintic
preserve
pf_comp_2w reject_pq

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "Piecewise Quintic"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_pq_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "Piecewise Quintic - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_pq_expert.pdf", as(pdf) replace
restore

* Piecewise quintic size-adjusted

preserve
pf_comp_2w reject_pq_sa

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "Piecewise Quintic (Type I Error-Adjusted)"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_pq_sa_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "Piecewise Quintic (Type I Error-Adjusted) - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_pq_sa_expert.pdf", as(pdf) replace
restore

*Rdrobust, bias corrected, MSE

preserve
pf_comp_2w reject_bc

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "CCT Robust"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_bc_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "CCT Robust - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_bc_expert.pdf", as(pdf) replace

restore

*Rdrobust, theoretical bandwidth adjusted for asymptotic bias

preserve
pf_comp_2w reject_c_theor_bw

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "CCT (Theor. BW, Bias)"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_c_theor_bw_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "CCT (Theor. BW, Bias) - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_c_theor_bw_expert.pdf", as(pdf) replace

restore


*Rdrobust, theoretical bandwidth, robust SEs, bias-correction

preserve
pf_comp_2w reject_r_theor_bw

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "CCT Robust (Theror. BW)"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_r_theor_bw_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "CCT Robust (Theor. BW) - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_r_theor_bw_expert.pdf", as(pdf) replace

restore

* Rdrobust, bias-corrected size-adjusted
preserve
pf_comp_2w reject_bc_sa
twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "CCT Robust (Type I Error-Adjusted)"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_bc_sa_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "CCT Robust (Type I Error-Adjusted) - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")
graph export "${output}/pf_diff_2w_bc_sa_expert.pdf", as(pdf) replace
restore

*Rdrobust, conventional, IK
preserve
pf_comp_2w reject_cik

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "IK"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_ik_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "IK - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_ik_expert.pdf", as(pdf) replace

restore

*Rdrobust, conventional, IK with theoretically optimal bandwidth
preserve
pf_comp_2w reject_cik_theor_bw

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "IK (Theor. BW)"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_ik_theor_bw_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "IK (Theor. BW) - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_ik_theor_bw_expert.pdf", as(pdf) replace

restore

* IK size-adjusted
preserve
pf_comp_2w reject_cik_sa

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "IK (Type I Error-Adjusted)"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_ik_sa_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "IK (Type I Error-Adjusted) - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_ik_sa_expert.pdf", as(pdf) replace

restore

*Armstrong & Kolesar: Taylor Class (true)
preserve
pf_comp_2w rdh_taylor_true_reject

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "AK (True Derivative)"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_rdhon_t_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "AK (True Derivative) - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_rdhon_t_expert.pdf", as(pdf) replace
restore

*Armstrong & Kolesar: Taylor Class (rule of thumb)
preserve
pf_comp_2w rdh_taylor_rot_reject

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O) lpattern(dash)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "AK"))  ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_rdhon_t_rot_expert.pdf", as(pdf) replace

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "AK - Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_rdhon_t_rot_expert.pdf", as(pdf) replace
restore

* Combined pf_comp graphs with solid/hollow indicating statistically significant differences

* Experts vs PQ and IK and CCT robust and AK (Taylor, rule of thumb) 
preserve
pf_comp_2w reject_pq
keep disc betar diffSignif
rename betar betaPQ
rename diffSignif diffSignifPQ
tempfile a
save "`a'", replace
restore
preserve
pf_comp_2w reject_bc 
keep disc betar diffSignif
rename betar betaCCT
rename diffSignif diffSignifCCT
tempfile b
save "`b'", replace
restore
preserve
pf_comp_2w reject_cik 
keep disc betar diffSignif
rename betar betaIK
rename diffSignif diffSignifIK
tempfile c
save "`c'", replace
restore
preserve
pf_comp_2w rdh_taylor_rot_reject
rename betar betaAK
rename diffSignif diffSignifAK

merge 1:1 disc using "`a'", nogen
merge 1:1 disc using "`b'", nogen
merge 1:1 disc using "`c'", nogen

twoway (scatter betay discc, msymbol(+))  ///
(scatter betaPQ discc if diffSignifPQ == 1, msymbol(O) lpattern(dash)) ///
(scatter betaIK discc if diffSignifIK == 1, msymbol(D) lpattern(dash)) ///
(scatter betaCCT discc if diffSignifCCT == 1, msymbol(T) lpattern(dash)) ///
(scatter betaAK discc if diffSignifAK == 1, msymbol(S) lpattern(dash)) ///
(scatter betaPQ discc if diffSignifPQ == 0, msymbol(Oh) lpattern(dash)) ///
(scatter betaIK discc if diffSignifIK == 0, msymbol(Dh) lpattern(dash)) ///
(scatter betaCCT discc if diffSignifCCT == 0, msymbol(Th) lpattern(dash)) ///
(scatter betaAK discc if diffSignifAK == 0, msymbol(Sh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betaPQ discc, msymbol(none) lpattern(dash))  ///
(connected betaIK discc, msymbol(none) lpattern(dash))  ///
(connected betaCCT discc, msymbol(none) lpattern(dash))  ///
(connected betaAK discc, msymbol(none) lpattern(dash)),  ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0)) ///
legend(rows(2) order(1 "Experts (Small Bins)" 2 "PQ" 3 "IK" 4 "CCT Robust" 5 "AK")) xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace)
graph export "${output}/pf_comp_2w_all_estimators_expert.pdf", as(pdf) replace
restore

* Experts vs IK and CCT with the theoretically optimal bandwidth (and bias for CCT), and AK with true derivative bounds
* Include RDRobust default for CCT comparison
preserve
pf_comp_2w reject_cik_theor_bw 
keep disc betar diffSignif
rename betar betaIK
rename diffSignif diffSignifIK
tempfile a
save "`a'", replace
restore
preserve
pf_comp_2w reject_c_theor_bw 
keep disc betar diffSignif
rename betar betaCCTtheor
rename diffSignif diffSignifCCTtheor
tempfile b
save "`b'", replace
restore
preserve
pf_comp_2w reject_r_theor_bw 
keep disc betar diffSignif
rename betar betaCCTrTheor
rename diffSignif diffSignifCCTrTheor
tempfile c
save "`c'", replace
restore
preserve
pf_comp_2w reject_c
keep disc betar diffSignif
rename betar betaCCT
rename diffSignif diffSignifCCT
tempfile d
save "`d'", replace
restore
preserve
pf_comp_2w rdh_taylor_true_reject
rename betar betaAK
rename diffSignif diffSignifAK

merge 1:1 disc using "`a'", nogen
merge 1:1 disc using "`b'", nogen
merge 1:1 disc using "`c'", nogen
merge 1:1 disc using "`d'", nogen

twoway (scatter betay discc, msymbol(+))  ///
(scatter betaCCTtheor discc if diffSignifCCTtheor == 1, msymbol(T) lpattern(dash)) ///
(scatter betaIK discc if diffSignifIK == 1, msymbol(O) lpattern(dash)) ///
(scatter betaAK discc if diffSignifAK == 1, msymbol(D) lpattern(dash)) ///
(scatter betaCCTtheor discc if diffSignifCCTtheor == 0, msymbol(Th) lpattern(dash)) ///
(scatter betaIK discc if diffSignifIK == 0, msymbol(Oh) lpattern(dash)) ///
(scatter betaAK discc if diffSignifAK == 0, msymbol(Dh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betaCCTtheor discc, msymbol(none) lpattern(dash))  ///
(connected betaIK discc, msymbol(none) lpattern(dash))  ///
(connected betaAK discc, msymbol(none) lpattern(dash)),  ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0)) ///
legend(order(1 "Experts (Small Bins)" 2 "CCT (Theor. BW, Bias)" 3 "IK (Theor. BW)" 4 "AK (True Deriv.)"))  xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace)
graph export "${output}/pf_comp_2w_theoretical_estimators_expert_cct_ik_ak.pdf", as(pdf) replace

twoway (scatter betay discc, msymbol(+))  ///
(scatter betaCCTtheor discc if diffSignifCCTtheor == 1, msymbol(T) lpattern(dash)) ///
(scatter betaCCTrTheor discc if diffSignifCCTrTheor == 1, msymbol(O) lpattern(dash)) ///
(scatter betaCCT discc if diffSignifCCTtheor == 0, msymbol(Th) lpattern(dash)) ///
(scatter betaCCTrTheor discc if diffSignifCCTrTheor == 0, msymbol(Oh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betaCCTtheor discc, msymbol(none) lpattern(dash))  ///
(connected betaCCTrTheor discc, msymbol(none) lpattern(dash)),  ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0)) ///
legend(order(1 "Experts (Small Bins)" 2 "CCT (Theor. BW, Bias)" 3 "CCT Robust (Theor. BW)"))  xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace)
graph export "${output}/pf_comp_2w_theoretical_estimators_expert_alt.pdf", as(pdf) replace

twoway (scatter betay discc, msymbol(+))  ///
(scatter betaCCT discc if diffSignifCCT == 1, msymbol(T) lpattern(dash)) ///
(scatter betaCCTrTheor discc if diffSignifCCTrTheor == 1, msymbol(O) lpattern(dash)) ///
(scatter betaCCTtheor discc if diffSignifCCTtheor == 1, msymbol(D) lpattern(dash)) ///
(scatter betaCCT discc if diffSignifCCT == 0, msymbol(Th) lpattern(dash)) ///
(scatter betaCCTrTheor discc if diffSignifCCTrTheor == 0, msymbol(Oh) lpattern(dash)) ///
(scatter betaCCTtheor discc if diffSignifCCTtheor == 0, msymbol(Dh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betaCCT discc, msymbol(none) lpattern(dash))  ///
(connected betaCCTrTheor discc, msymbol(none) lpattern(dash)) ///
(connected betaCCTtheor discc, msymbol(none) lpattern(dash)), ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0)) ///
legend(order(1 "Experts (Small Bins)" 2 "CCT" 3 "CCT Robust (Theor. BW)" 4 "CCT (Theor. BW & BC)")) ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace)
graph export "${output}/pf_comp_2w_cct_theoretical_estimators_expert.pdf", as(pdf) replace
restore

* Experts vs IK and CCT robust (both size-adjusted)
preserve
pf_comp_2w reject_cik_sa
keep disc betar diffSignif
rename betar betaIK
rename diffSignif diffSignifIK
tempfile a
save "`a'", replace
restore
preserve
pf_comp_2w reject_bc_sa
rename betar betaCCT
rename diffSignif diffSignifCCT
merge 1:1 disc using "`a'", nogen

twoway (scatter betay discc, msymbol(+))  ///
(scatter betaIK discc if diffSignifIK == 1, msymbol(O) lpattern(dash)) ///
(scatter betaCCT discc if diffSignifCCT == 1, msymbol(D) lpattern(dash)) ///
(scatter betaIK discc if diffSignifIK == 0, msymbol(Oh) lpattern(dash)) ///
(scatter betaCCT discc if diffSignifCCT == 0, msymbol(Dh) lpattern(dash)) ///
(connected betay discc, msymbol(none) lpattern(solid))  ///
(connected betaIK discc, msymbol(none) lpattern(dash))  ///
(connected betaCCT discc, msymbol(none) lpattern(dash)),  ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0)) ///
legend(order(1 "Experts (Small Bins)" 2 "IK (Type I Error-Adjusted)" 3 "CCT Robust (Type I Error-Adjusted)"))  xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace)

graph export "${output}/pf_comp_2w_all_sa_estimators_expert.pdf", as(pdf) replace
restore

*Rdrobust, conventional, CER
preserve
pf_comp_2w reject_c_cer

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O)) ///
(connected betay discc, msymbol(none) lpattern(solid)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh)) ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "CCT Conventional CER-Optimal BW")) ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_CCT_c_cer_expert.pdf", as(pdf) replace
restore

*Rdrobust, robust, CER
preserve
pf_comp_2w reject_r_cer 

twoway (scatter betay discc, msymbol(+)) ///
(scatter betar discc if diffSignif == 1, msymbol(O)) ///
(connected betay discc, msymbol(none) lpattern(solid)) ///
(scatter betar discc if diffSignif == 0, msymbol(Oh)) ///
(connected betar discc, msymbol(none) lpattern(dash)),  ///
legend(order(1 "Experts" 2 "CCT Robust CER-Optimal BW")) ///
xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_CCT_bc_cer_expert.pdf", as(pdf) replace
restore

graph close _all

preserve
replace y = y * reject_pq
pf_comp_2w rdh_taylor_rot_reject

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "AK - Experts & PQ") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_ak_v_pq_expert_prop.pdf", as(pdf) replace
restore

preserve
replace y = y * reject_bc
pf_comp_2w rdh_taylor_rot_reject

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "AK - Experts & CCT Robust") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_ak_v_bc_expert_prop.pdf", as(pdf) replace
restore

preserve
replace y = y * reject_cik
pf_comp_2w rdh_taylor_rot_reject

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "AK - Experts & IK") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_ak_v_ik_expert_prop.pdf", as(pdf) replace

twoway (connected betar discc, msymbol(smx) lpattern(dash)) ///
(connected betay discc, msymbol(Oh) lpattern(solid)),  ///
legend(lab (1 "AK")  lab(2 "Experts & IK"))  xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace) ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0))
graph export "${output}/pf_comp_2w_ak_ik_expert_prop.pdf", as(pdf) replace
restore

preserve
replace y = y * rdh_taylor_rot_reject
pf_comp_2w rdh_taylor_rot_reject

twoway (connected diff disc, msymbol(smx)) ///
(rcap cl cu disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "AK - Experts & AK") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude")

graph export "${output}/pf_diff_2w_ak_v_rdh_expert_prop.pdf", as(pdf) replace
restore

* Combined plot of all estimators w/ experts
preserve
replace y = y * reject_pq
pf_comp_2w rdh_taylor_rot_reject
keep disc betay diffSignif
rename diffSignif diffSignifPQ
rename betay betaPQExp
tempfile a
save "`a'", replace
restore
preserve
replace y = y * reject_bc
pf_comp_2w rdh_taylor_rot_reject
keep disc betay diffSignif
rename diffSignif diffSignifCCTr
rename betay betaCCTrExp
tempfile b
save "`b'", replace
restore
preserve
replace y = y * reject_cik
pf_comp_2w rdh_taylor_rot_reject
keep disc betay diffSignif
rename diffSignif diffSignifIK
rename betay betaIKExp
tempfile c
save "`c'", replace
restore
preserve
replace y = y * rdh_taylor_rot_reject
pf_comp_2w rdh_taylor_rot_reject
rename diffSignif diffSignifAK
rename betay betaAKExp

merge 1:1 disc using "`a'", nogen
merge 1:1 disc using "`b'", nogen
merge 1:1 disc using "`c'", nogen

twoway (scatter betar discc, msymbol(+)) ///
(scatter betaPQExp discc if diffSignifPQ == 1, msymbol(O)) ///
(scatter betaIKExp discc if  diffSignifIK == 1, msymbol(T)) ///
(scatter betaCCTrExp discc if diffSignifCCTr == 1, msymbol(D)) ///
(scatter betaAKExp discc if diffSignifAK == 1, msymbol(S)) ///
(scatter betaPQExp discc if diffSignifPQ == 0, msymbol(Oh)) ///
(scatter betaIKExp discc if diffSignifIK == 0, msymbol(Th)) ///
(scatter betaCCTrExp discc if diffSignifCCTr == 0, msymbol(Dh)) ///
(scatter betaAKExp discc if diffSignifAK == 0, msymbol(Sh)) ///
(line betar discc, lpattern(line)) ///
(line betaPQExp discc, msymbol(none) lpattern(dash)) ///
(line betaIKExp discc, msymbol(none) lpattern(dash)) ///
(line betaCCTrExp discc, msymbol(none) lpattern(dash)) ///
(line betaAKExp discc, msymbol(none) lpattern(dash)), ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0)) yscale(titlegap(*-30)) ///
legend(rows(2) order(1 "AK" 2 "Experts & PQ" 3 "Experts & IK" 4 "Experts & CCT Robust" 5 "Experts & AK"))  xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace)
graph export "${output}/pf_comp_2w_experts_estimators_prop.pdf", as(pdf) replace
restore

graph close _all



* IK with 2.18 critical values (w/ and w/o DGP omniscience)
replace y = rdh_taylor_rot_reject
replace pid = -1 * _n if human == 1

preserve
pf_comp_2w reject_cik_sa_218 
keep disc betar diffSignif
rename diffSignif diffSignifIK218
rename betar betaIK218
tempfile a
save "`a'", replace
restore
preserve
pf_comp_2w reject_cik_theor_bw_sa_218
keep disc discc betar betay diffSignif
rename diffSignif diffSignifIKTBW218
rename betar betaIKTBW218
rename betay betaAK

merge 1:1 disc using "`a'", nogen

twoway (scatter betaAK discc, msymbol(+)) ///
(scatter betaIK218 discc if diffSignifIK218 == 1, msymbol(O)) ///
(scatter betaIKTBW218 discc if  diffSignifIKTBW218 == 1, msymbol(T)) ///
(scatter betaIK218 discc if diffSignifIK218 == 0, msymbol(Oh)) ///
(scatter betaIKTBW218 discc if diffSignifIKTBW218 == 0, msymbol(Th)) ///
(line betaAK discc, lpattern(line)) ///
(line betaIK218 discc, msymbol(none) lpattern(dash)) ///
(line betaIKTBW218 discc, msymbol(none) lpattern(dash)), ///
ymtick(0.05) ymlabel("0.05", labsize(small) angle(0)) ///
ylabel(, angle(0)) ///
legend(rows(2) order(1 "AK" 2 "IK (Type-I Error Adjusted)" 3 "IK (Type-I Error Adjusted, Theor. BW)"))  xlabel(, valuelabel) ytitle("Reject No Discontinuity") ///
xtitle("Discontinuity Magnitude") name(grapha, replace)
graph export "${output}/pf_comp_2w_ak_v_ik_218.pdf", as(pdf) replace
restore

* Experts vs non-experts
preserve
use "${dat}/expert_merged_rd_estimates_micro.dta", clear
gen expert = 1
cap drop _merge
cap drop disc

* Append in non-experts
append using "${dat}/survey_merged_rd_estimates_micro"
keep if playertreatment_group == "A"
replace expert = 0 if expert == .

*Modify discontinuity variable:
 
replace abs_disc = round(abs_disc,0.0001)

cap drop disc
gen disc  = 0 if abs_disc<=0.01
replace disc = 4 if abs_disc>=0.89 & abs_disc<=0.91
replace disc = 5 if abs_disc>=1.49
replace disc = 3 if abs_disc>=0.53 & abs_disc<=0.55
replace disc = 2 if abs_disc>=0.32 & abs_disc<=0.33
replace disc = 1 if abs_disc>=0.19 & abs_disc<=0.2

label define disc_lab 0 "0" 1 "0.1944" 2 "0.324" 3 "0.54" 4 "0.9" 5 "1.5"
label values disc disc_lab
tabulate disc, gen(d)

egen player = group(pid)

reg y d1 d2 d3 d4 d5 d6 if expert == 1, nocons vce(cluster player)
forvalues num = 1/6 {
	local se`num'E = _se[d`num']
	local beta`num'E = _b[d`num']
					}
reg y d1 d2 d3 d4 d5 d6 if expert == 0, nocons vce(cluster player)					
forvalues num = 1/6 {
	local se`num'N = _se[d`num']
	local beta`num'N = _b[d`num']

	*Difference
	local diff`num'E =  `beta`num'E' - `beta`num'N'
	local se_diff =  sqrt((`se`num'E'^2) + (`se`num'N'^2))
	local cl`num'E = `diff`num'E' - 1.96*`se_diff'
	local cu`num'E = `diff`num'E' + 1.96*`se_diff'
					}						
					
drop _all
set obs 6

gen disc = _n - 1
label values disc disc_lab

*Create cardinal discontinuity
gen discc = 0 if disc == 0
replace discc = 0.1944 if disc == 1
replace discc = 0.324 if disc == 2
replace discc = 0.54 if disc == 3
replace discc = 0.9 if disc == 4
replace discc = 1.5 if disc == 5

gen betaE = .
gen betaN = .
gen diffE = .
gen cuE = .
gen clE = .
gen diffSignif = .

forvalues num = 1/6 { 

	replace betaE = `beta`num'E' if disc == `num'-1 
	replace betaN = `beta`num'N' if disc == `num'-1 
	replace diffE = `diff`num'E' if disc == `num'-1
	replace cuE = `cu`num'E' if disc == `num'-1
	replace clE = `cl`num'E' if disc == `num'-1
}

replace diffSignif = cuE < 0 | clE > 0

twoway (connected diffE disc, msymbol(smx)) ///
(rcap clE cuE disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "Experts - Non-Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude") title("Small Bins")
graph export "${output}/pf_diff_expert_nonexpert_rd.pdf", as(pdf) replace
graph close _all
restore


* Experts (QSS) and non-experts (Large bins)
preserve
use "${dat}/Expert Princeton/Expert Princeton part1.dta", clear
gen expert = 1
cap drop _merge
cap drop disc

* Append in non-experts
append using "${dat}/survey_merged_rd_estimates_micro"
keep if playertreatment_group == "B"
replace expert = 0 if expert == .

*Modify discontinuity variable:
 
replace abs_disc = round(abs_disc,0.0001)

cap drop disc
gen disc  = 0 if abs_disc<=0.01
replace disc = 4 if abs_disc>=0.89 & abs_disc<=0.91
replace disc = 5 if abs_disc>=1.49
replace disc = 3 if abs_disc>=0.53 & abs_disc<=0.55
replace disc = 2 if abs_disc>=0.32 & abs_disc<=0.33
replace disc = 1 if abs_disc>=0.19 & abs_disc<=0.2

label define disc_lab 0 "0" 1 "0.1944" 2 "0.324" 3 "0.54" 4 "0.9" 5 "1.5"
label values disc disc_lab
tabulate disc, gen(d)

egen player = group(pid)

reg y d1 d2 d3 d4 d5 d6 if expert == 1, nocons vce(cluster player)
forvalues num = 1/6 {
	local se`num'E = _se[d`num']
	local beta`num'E = _b[d`num']
					}
reg y d1 d2 d3 d4 d5 d6 if expert == 0, nocons vce(cluster player)					
forvalues num = 1/6 {
	local se`num'N = _se[d`num']
	local beta`num'N = _b[d`num']

	*Difference
	local diff`num'E =  `beta`num'E' - `beta`num'N'
	local se_diff =  sqrt((`se`num'E'^2) + (`se`num'N'^2))
	local cl`num'E = `diff`num'E' - 1.96*`se_diff'
	local cu`num'E = `diff`num'E' + 1.96*`se_diff'
					}						
					
drop _all
set obs 6

gen disc = _n - 1
label values disc disc_lab

*Create cardinal discontinuity
gen discc = 0 if disc == 0
replace discc = 0.1944 if disc == 1
replace discc = 0.324 if disc == 2
replace discc = 0.54 if disc == 3
replace discc = 0.9 if disc == 4
replace discc = 1.5 if disc == 5

gen betaE = .
gen betaN = .
gen diffE = .
gen cuE = .
gen clE = .

forvalues num = 1/6 { 

	replace betaE = `beta`num'E' if disc == `num'-1 
	replace betaN = `beta`num'N' if disc == `num'-1 
	replace diffE = `diff`num'E' if disc == `num'-1
	replace cuE = `cu`num'E' if disc == `num'-1
	replace clE = `cl`num'E' if disc == `num'-1
}


twoway (connected diffE disc, msymbol(smx)) ///
(rcap clE cuE disc, msymbol(smx) yline(0)) ///
, legend(lab(1 "Experts - Non-Experts") lab(2 "CI")) ///
name(graphA, replace) xlabel(, valuelabel) xtitle("Discontinuity Magnitude") title("Large Bins")

graph export "${output}/pf_diff_expert_qss_nonexpert_bigbins_rd.pdf", as(pdf) replace
graph close _all
restore


graph close _all

log using "${logs}/estimators_v_human_rd_experts_contingency_tables.log", replace text name(rd_cont)

* Create contingency tables for RD estimators (Fisher's exact test). Overall and by discontinuity level.
use "`full'", clear
gen abs_disc_str = string(abs_disc)
keep if playertreatment_group == "A"
foreach est in rdh_taylor_true_reject rdh_taylor_rot_reject reject_pq reject_bc reject_cik {
	di "Contingency tables for player response and and `est'."

	if "`est'" == "reject_pq" {
		di "Piecewise Quintic"
	}
	if "`est'" == "reject_bc" {
		di "CCT Robust "
	}
	if "`est'" == "rdh_taylor_true_reject" {
		di = "AK (Taylor class, true bound)"
	}
	if "`est'" == "rdh_taylor_rot_reject" {
		di = "AK (Taylor class, ROT bound)"
	}
	if "`est'" == "reject_cik" {
		di = "IK"
	}

	di "Overall contingency table"
	tab y `est', exact all
	di "Disc 0"
	tab y `est' if abs_disc_str == "0", exact all
	di "Disc 0.1944"
	tab y `est' if abs_disc_str == ".1944", exact all
	di "Disc 0.324"
	tab y `est' if abs_disc_str == ".324", exact all
	di "Disc 0.54"
	tab y `est' if abs_disc_str == ".54", exact all
	di "Disc 0.9"
	tab y `est' if abs_disc_str == ".9", exact all
	di "Disc 1.5"
	tab y `est' if abs_disc_str == "1.5", exact all
}

log close rd_cont

log close
